﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Maticsoft.Common.DEncrypt;
using Maticsoft.Common;

namespace Maticsoft.Web.Admin
{
    public partial class Login : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string userName = SqlFilter(UserName.Text.Trim());
            string password = DEncrypt.Encrypt(Password.Text.Trim());
            string code = Vcode.Text.Trim().ToUpper();
            if (code == Request.Cookies["CheckCode"].Value)
            {
                BLL.Members bll = new BLL.Members();
                DataSet ds = bll.GetMemberByUserNamePassword(userName, password);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    Session["UserId"] = ds.Tables[0].Rows[0]["UserId"].ToString();
                    Session["ManagerName"] = ds.Tables[0].Rows[0]["UserName"].ToString();
                    Session["GroupName"] = ds.Tables[0].Rows[0]["GroupName"].ToString();
                    Session["GroupId"] = ds.Tables[0].Rows[0]["GroupId"].ToString();

                    Cookie.SetCookieValue("UserId", ds.Tables[0].Rows[0]["UserId"].ToString());

                    Response.Redirect("Index.aspx");
                }
                else
                {
                    MessageBox.ShowAndRedirect(this.Page, "用户名或者密码错误，请重新输入！", "Login.aspx");
                }
            }
            else
            {
                MessageBox.ShowAndRedirect(this.Page, "验证码错误！", "Login.aspx");
            }
        }
    }
}